function StartCapture(mode)
{
	if( mode == "still")
		StartCaptureStill();
	
	if( mode == "timelapse")
		StartCaptureTime();
		
	if( mode == "group")
		StartCaptureGroup();
		
}

function StartCaptureStill()
{
	flashpoint();

	printf('# API: StartCapture() ');
	printf('# Continuously take still pictures by monitoring ipip bit. ');
	printf('# When done call "RunScript("erase.csm") to erase pictures. ');
	printf('# (produce erase.csm with the EraseFile button )')
	printf('# To change the number of pictures taken, modify imageCount. ');
	printf('# Note that this script contains no check for a full disk.');
	printf('# To take pictures forever, call the erase.csm script.');
	printf('# at the end of this script, then call this script again ');
	printf('# from erase.csm.');
	printf(' ');

	writeMenu('"StartCaptureStill"' , '"CMD"','"StartCapture(still)"');
	writeVariables();
	printf('# StartCapture parameters ');
	printf('declare u: imageCount, timerDelay, captureSize ');
	printf('declare u: startCount,autoCount' );
	printf('declare s: groupName' );

	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZStill.txt"');
	writeFileOpen();
		
	
	printf('# takes pictures by monitoring ipip bit ');
	printf('# when done call "RunScript("erase.csm") to erase pictures ');
	printf('# to modify picture taking note the variables below ');
	printf('# imageCount	: number  of pictures to take ');
	printf(' ');	
	printf(' imageCount = 5 ');
	
	
	printf(' ');
	printf(' # take pictures  ****************************************');

	printf(' count = 0 ');
	printf(' # set capture mode to group ');
	printf(' SetCaptureMode(still) ');

	printf(' if status == 0 ');
	printf(' count = count + 1 ');
	printf(' end');

	printf('<br>');
	printf(' # PICTURE TAKING LOOP **** ');
	printf('TAKEANOTHERPICTURE:');
	printf(' FileClose( fd )');
	printf(' FileOpen( 2, outFile , 1, fd ) ');
	printf(' ');
	
	printf(' status=StartCapture() ');

	printf(' # *****************************');
	printf(' # THIS CODE MAY BE TAKEN OUT AND REPLACED ');
	printf(' # WITH A Wait(5000) statement ');
	printf(' WAITFOR_IPIP:');
	printf(' GetCameraStatus(system,capture,vendor) ');
	printf(' Display(".")');
	printf(' if system & 0x10000000 ');
	printf(' Wait(5000) ' );
	printf(' goto WAITFOR_IPIP ' );
	printf(' end');
	printf(' DisplayClear() ');
	printf(' # *****************************');


	printf(' GetTimeString(time) ');
	printf(' Write(fd,time,"[",count,"]: ") ');
	
	printf(' DisplayLine("StCapt[",status,"] (",count,")" ) ');
	printf(' Write(fd,"StCapt[",status,"] ") ');

	printf(' if status == 0 ');
	printf(' count = count + 1 ');
	printf(' WriteLine(fd, count," pictures taken ") ');
	printf(' end');
	
	printf(' if status != 0 ');
	printf(' WriteLine(fd, "PICTURE NOT TAKEN ") ');
	printf(' end');

	printf(' Wait(1) ');
	printf(' if count < imageCount');
	printf(' goto TAKEANOTHERPICTURE');
	printf(' end');

	printf('');
	printf('# FINISHED PICTURES, call EndCapture **********');
	printf(' EndCapture()');


	printf(' FileClose( fd )');
	
	printf(' # uncomment to call "erase.csm" and  erase files******* ');	
	printf('# RunScript("erase.csm")');
	printf(' end');



}

function StartCaptureTime()
{
	flashpoint();

	printf('# API: StartCapture(tlap) ');
	printf('# Take time lapse pictures. ');
	printf('# to vary number of pictures, change "imageCount" line ');
	printf('# to vary elapsed time between shots, change timerDelay');
	printf('# Note that this script contains no check for a full disk.');
	printf('# To take pictures forever, call the erase.csm script.');
	printf('# (produce erase.csm with the EraseFile button )')

	printf('# at the end of this script, then call this script again ');
	printf('# from erase.csm.');
	
	printf(' ');

	writeMenu('"StartCapture(tlap)"' , '"CMD"','"StartCapture(tlap)"');
	writeVariables();
	printf('# StartCapture parameters ');
	printf('declare u: imageCount, timerDelay, captureSize ');
	printf('declare u: startCount,autoCount' );
	printf('declare s: groupName' );

	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZTime.txt"');
	writeFileOpen();
		
	
	printf('# modify these values to change picture taking ');
	printf(' imageCount = 15 ');
	printf(' timerDelay = 60 ');
	printf(' captureSize = 1 ');
	
	printf(' # take pictures  *********************************');

	printf(' # set capture mode to time lapse ');
	printf(' SetCaptureMode(tlap) ');

	printf('<br>');	
	printf(' WriteLine(fd,"about to take ",imageCount," time lapse pictures") ');
	printf(' WriteLine(fd,timerDelay," secs apart ",captureSize," captureSize") ');
		
	printf(' status=StartCapture(imageCount,timerDelay,captureSize) ');

	printf(' GetTimeString(time) ');	

	printf(' if status == 0 ');
	printf(' WriteLine(fd,time,"StCapt[",status,"] ",imageCount," pictures taken " ) ');
	printf(' end');
	
	printf(' if status != 0 ');
	printf(' WriteLine(fd,time, "PICTURES NOT TAKEN ") ');
	printf(' end');

	printf('');
	printf('# FINISHED PICTURES, call EndCapture **********');
	printf(' EndCapture()');


	printf(' FileClose( fd )');
	
	printf(' ');
	printf('# uncomment to call "erase.csm" ******* ');	
	printf('# insert a RunScript("---" ) in "erase.csm" and call this file ');
	printf('# RunScript("erase.csm")');


}


function StartCaptureGroup()
{

	flashpoint();
	
	printf('# API: StartCapture(group) ');
	printf('# takes group pictures  ');
	printf('# when done call "RunScript("erase.csm") to erase pictures ');
	printf('# (produce erase.csm with the EraseFile button )')
	printf('# to vary number of pictures, change "imageCount" value ');	
	printf('# startCount = "grct" param of first picture ');
	printf('# sucessive shots increment by 1 if autoCount is non-zero ');
	printf(' ');
	
	writeMenu('"StartCapture(group)"' , '"CMD"','"StartCapture(group)"');
	writeVariables();
	printf('# StartCapture parameters ');
	printf('declare u: imageCount, timerDelay, captureSize ');
	printf('declare u: startCount,autoCount' );
	printf('declare s: groupName' );

	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZGroup.txt"');
	writeFileOpen();

	printf(' ');
	printf(' imageCount = 5 ');	
	printf(' groupName = "FLASHPNT" ');
	printf(' startCount = 10 ');
	printf(' autoCount = 1 ');
	
	printf(' # take pictures  *********************************');

	printf(' count = 0 ');
	printf(' # only set group mode ONCE ');
	printf(' SetCaptureMode(group) ');
	printf(' status=StartCapture(groupName,startCount,autoCount) ');

	printf(' KEEPONGOING: ');
	printf(' FileClose( fd ) ');
	printf(' FileOpen( 2, outFile , 1, fd ) ');

	printf(' GetTimeString(time) ');
	printf(' Write(fd,time,"[",count,"]:") ');

	printf(' # ***************************** ');
	printf(' WAITFOR_IPIP: ');
	printf(' GetCameraStatus(system,capture,vendor) ');
	printf(' Display(".") ');
	printf(' if system & 0x10000000 ');
	printf(' Wait(5000) ');
	printf(' goto WAITFOR_IPIP ');
	printf(' end ');
	printf(' DisplayClear() ');
	printf(' # ***************************** ');
	printf(' ');

	printf(' status=StartCapture() ');
	printf(' DisplayLine("StCapt[",status,"] (",count,")" ) ');

	printf(' if status==0 ');
	printf(' Write(fd,"StCapt[",status,"] ") ');
	printf(' WriteLine(fd, count," pictures taken ") ');
	printf(' count = count + 1 ');
	printf(' end ');

	printf(' if count < imageCount ');
	printf(' goto KEEPONGOING ');
	printf(' end ');


	printf('');
	printf('# FINISHED PICTURES, call EndCapture **********');
	printf(' EndCapture()');

	printf(' FileClose( fd )');
	
	printf(' ');
	printf('# uncomment to call "erase.csm" ******* ');	
	printf('# insert a RunScript("---" ) in "erase.csm" and call this file ');
	printf('# RunScript("erase.csm")');
	printf('exitscript');

}

